package models

import (
	"CMETO/utils"
	"time"
)

// 商品分类表
type GoodsType struct {
	// 分类Id
	Id int `json:"id" gorm:"column:id;type:int;auto_increment;primary_key;"`
	// 上级商品Id
	FId int `json:"fid" gorm:"column:fid;type:int;"`
	// 分类图标
	Icon string `json:"icon" gorm:"column:icon;type:varchar(250);"`
	// 分类名称
	Name string `json:"name" gorm:"column:name;type:varchar(40);"`
	// 分类描述
	Description string `json:"description" gorm:"column:description;type:varchar(120);"`
	// 状态
	Status int `json:"status" gorm:"column:status;type:int;"`
	// 创建时间
	CreateTime string `json:"create_time" gorm:"column:create_time;type:varchar(30);"`
	// 是否删除
	IsDelete  int         `json:"is_delete" gorm:"column:is_delete;type:int;"`
	Children  []GoodsType `json:"children" gorm:"foreignKey:fid;"`
	GoodsList []Goods     `json:"goodsList" gorm:"foreignKey:sid;"`
}

// 插入一批商品分类数据
func InsertMockGoodsType() {
	DB.Model(&GoodsType{}).Create([]GoodsType{
		{Id: 1, FId: 0, Name: "课程", Icon: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", Description: "课程", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 2, FId: 1, Name: "免费课程", Icon: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", Description: "免费课程", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 3, FId: 1, Name: "付费课程", Icon: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", Description: "付费课程", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 4, FId: 0, Name: "学习用品", Icon: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", Description: "学习用品", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 5, FId: 4, Name: "教材", Icon: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", Description: "教材", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 6, FId: 4, Name: "试卷", Icon: "http://resource.shuonihao.cn/cmeto/course/rolling_cover.jpg", Description: "试卷", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
	})
}
